<div [@routerTransition]>
    <div class="content d-flex flex-column flex-column-fluid">
        <sub-header [title]="'MaintainRecord' | localize" [description]="'MaintainRecord' | localize">
            <div role="actions"></div>
        </sub-header>

        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div>
                                <div class="row align-items-center mb-4">
                                    <!-- 问题描述查询 -->
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('bugDescriptionSearch')}}/{{l('deviceName')}}</label>
                                            <!-- /{{l('outId')}} -->
                                            <div class="input-group">
                                                <input (keyup.enter)="getOperationsRecord($event)" [(ngModel)]="filterText" name="metaName" autoFocus
                                                    class="form-control m-input" type="text"
                                                    [placeholder]="l('search')">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- 时间范围筛选 -->
                                    <div class="col-2" style="position:relative;">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('DateRange')}}</label>
                                            <date-range-picker name="SampleDateRangePicker" needInitDate="true"
                                                [(startDate)]="StartTime" [(endDate)]="EndTime" [showButton]="false">
                                            </date-range-picker>
                                        </div>
                                    </div>
                                    <!-- 状态 -->
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('auditStatus')}}</label>
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="statusSelect"
                                                    name="metaTypeSelect2">
                                                    <option value="">{{l('AllTypes')}}</option>
                                                    <option value="0">{{l('unsolved')}}</option>
                                                    <option value="1">{{l('resolving')}}</option>
                                                    <option value="2">{{l('resolved')}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2" *ngIf="!appSession.tenant">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('TenantSelection')}}</label>
                                            <div class="input-group">
                                                <!-- <select #TenantCombobox class="form-control" [(ngModel)]="tenantId" name="tenantId"
                                                [disabled]="!tenants" [attr.data-live-search]="true" jq-plugin="selectpicker"
                                                (change)="getCategories()">
                                                <option value="">{{l("HOST")}}</option>
                                                <option *ngFor="let tenant of tenants" [value]="tenant.id">{{tenant.name+'('+tenant.tenancyName+')'}}</option>
                                            </select> -->
                                                <select class="form-control" [(ngModel)]="tenantId" name="tenantId"
                                                    (change)="getCategories()">
                                                    <option value="">{{l("HOST")}}</option>
                                                    <option *ngFor="let tenant of tenants" [value]="tenant.id">
                                                        {{tenant.name+'('+tenant.tenancyName+')'}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('QuestionType')}}</label>
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="questionTypeId"
                                                    name="QuestionType">
                                                    <option value="">{{l("AllTypes")}}</option>
                                                    <option *ngFor="let questionType of questionTypeList"
                                                        [value]="questionType.id">{{questionType.name}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2 text-right">
                                        <label style="display:block;">&nbsp;</label>
                                        <div class="form-group align-items-center">
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading"
                                                    (click)="getOperationsRecord()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <!--<Primeng-Datatable-Start>-->
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <!-- resizableColumns="primengTableHelper.resizableColumns" -->
                            <p-table #dataTable (onLazyLoad)="getOperationsRecord($event)"
                                [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage" [paginator]="false" [lazy]="true"
                                [(selection)]="selectedList" [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th style="width: 10%">{{l('Actions')}}</th>
                                        <th style="width: 5.0em">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th>
                                        <th style="width:5%">{{l('RecordId')}}</th>
                                        <th pSortableColumn="startTime" style="width:12%;">
                                            {{l('startTime')}}
                                            <p-sortIcon field="startTime"></p-sortIcon>
                                        </th>
                                        <th style="width:8%;">{{l('totalMinutes')}}</th>
                                        <th style="width:8%;">{{l('TenancyName')}}</th>
                                        <th style="width:8%;">{{l('Device')}}</th>


                                        <!-- <th pSortableColumn="endTime" style="width:12%;">
                                        {{l('endTime')}}
                                        <p-sortIcon field="endTime"></p-sortIcon>
                                    </th> -->
                                        <th>{{l('bugDescription')}}</th>
                                        <th>{{l('solution')}}</th>
                                        <!-- <th style="width:8%;">{{l('theOne')}}</th> -->
                                        <!-- <th style="width:7%;">{{l('totalMinutes')}}</th> -->
                                        <th style="width:8%">{{l('auditStatus')}}</th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record">
                                        <td>
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary" dropdownToggle
                                                    data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li>
                                                        <a class="icon-bianji dropdown-item"
                                                            (click)="editRecord(record)">{{l('Edit')}}</a>
                                                    </li>
                                                    <li>
                                                        <a class="icon-icon-test dropdown-item"
                                                            (click)="deleteRecord(record)">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <td style="width: 5.0em">
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td>
                                        <td> {{transIndex(i,paginator)}}</td>
                                        <td>
                                            <span>{{moment(record.startTime).format('YYYY-MM-DD HH:mm:ss')}}</span>
                                        </td>
                                        <!-- <td>
                                        <span *ngIf="record.endTime">{{moment(record.endTime).format('YYYY-MM-DD
                                            HH:mm:ss')}}
                                        </span>
                                    </td> -->
                                        <td>
                                            <span>{{record.totalMinutes}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.tenantName}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.deviceName}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.question}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.action}}</span>
                                        </td>
                                        <!-- <td>
                                        <span>{{record.operator}}</span>
                                    </td>
                                    <td>
                                        <span>{{record.totalMinutes}}{{l("minutes")}}</span>
                                    </td> -->
                                        <td>
                                            <span *ngIf="record.optStatus==0"
                                                style="color:#ccc;">{{record.optStatus|deviceStatus}}</span>
                                            <span *ngIf="record.optStatus==1"
                                                style="color:#DD0000;">{{record.optStatus|deviceStatus}}</span>
                                            <span *ngIf="record.optStatus==2"
                                                style="color:#00DD00;">{{record.optStatus|deviceStatus}}</span>
                                        </td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="9" class="text-center">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/deviceHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getOperationsRecord($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>


                </div>
            </div>
        </div>
        <createOrEditDeviceRecordModal #createOrEditDeviceRecordModal (modalSave)="getOperationsRecord()">
        </createOrEditDeviceRecordModal>
    </div>
</div>